<?php


namespace App\Http\Server;


use App\Models\Delivery;

class DeliveryServer
{

    public function addDeliveryServer($id,$customer_id,$goods_id,$num,$now_date,$manufacturer_id,$cost_price,$sales_price,$total_price){
        if(isset($id) && !empty($id)){
            $model = Delivery::find($id);
        }else{
            $model = new Delivery();
        }
        $model->customer_id = $customer_id;
        $model->goods_id = $goods_id;
        $model->num = $num;
        $model->now_date = $now_date;
        $model->manufacturer_id = $manufacturer_id;
        $model->cost_price = $cost_price;
        $model->sales_price = $sales_price;
        $model->total_price = $total_price;
        $model->save();
        return ['status'=>200,'data'=>$model,'msg'=>'success'];
    }

    /**
     * 获取送货记录列表
     * @param $customer_name
     * @param $customer_phone
     */
    public function getDeliveryListServer($params,$per_page=10)
    {
        // 执行查询
        $users = Delivery::Search($params)->with(['goods','manufacturer','customer'])
            ->orderBy('id','desc')
            ->paginate($per_page)->toArray();
        return ['status'=>200,'data'=>$users['data'],'msg'=>'success'];
    }
}
